<?php
require_once "../../php/config/database.php";
require_once "../../php/user/userDb.php";
session_start();
$user = $_SESSION['user'];
$UserDb=new UserDb();
$data=$UserDb->queryUser($user);
$admin=$data[0]['admin'];

?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <link rel="shortcut icon" href="../ico/logo.ico" type="image/x-icon" />
    <title>协同办公</title>
    <link rel="stylesheet" href="../../static/css/bootstrap.css">
    <link rel="stylesheet" href="../../static/js/layui/css/layui.css">
    <link rel="stylesheet" href="../../static/css/font.css">
    <link rel="stylesheet" href="../../static/css/main.css">
    <style>


    </style>
</head>
<body>
<div id="logo"><div id="logo-img"><img src="../../static/imaegs/logo/logo2.png"></div>
    <div id="logo-right">
        <h5 ><i class="layui-icon" style="font-size: 18px; color: orange">&#xe645;</i>&nbsp;最新公告：<span id="notice"></span></h5>
    </div>
</div>
<div id="tiao">
    <div id="left"><a href="index.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe68e;</i>&nbsp;首页</a>
        <a href="task_list.php" style="border-bottom: 2px blue solid"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe6b2;</i>&nbsp;我的任务</a>
        <a href="file.php"> <i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe621;</i>&nbsp;我的文件</a>
        <a href="user_list.php"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe613;</i>&nbsp;成员信息</a></div>
    <div id="right"><a style="color:grey">您好！&nbsp;</a><input id="user" name="user" readonly="readonly" value="<?php echo $user ?>"><i class="layui-icon" style="font-size: 20px; color: #1E9FFF;">&#xe66f;</i><a href="">个人中心</a>&nbsp;&nbsp;<a onclick="out()">退出</a></div>
</div>

<div id="from_block">
<input style="display: none" type="text" id="admin" value="<?php echo $admin; ?>">
    <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
        <ul class="layui-tab-title">
            <li class="layui-this">我的小组任务</li>
            <li>我的个人任务</li>
            <li>添加我的任务</li>
        </ul>
        <div class="layui-tab-content" style="height: 200px;">
            <div class="layui-tab-item layui-show">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend>我接受的小组任务--<?php echo $user; ?></legend>
                        </fieldset>
                        <table class="layui-table" lay-data="{width: 1000, height:500, url:'../../php/user/select_task_user.php?user=<?php echo $user; ?>',  page:true, id:'idTest'}" lay-filter="demo">
                            <thead>
                            <tr>
                                <th lay-data="{field:'id', width:80, sort: true, fixed: true}">任务ID</th>
                                <th lay-data="{field:'task_admin', width:100}">管理员</th>
                                <th lay-data="{field:'task_content', width:150}">任务详情</th>
                                <th lay-data="{field:'task_time', width:180}">发布时间</th>
                                <th lay-data="{field:'time_over', width:150}">截至时间</th>
                                <th lay-data="{field:'complete', width:200}">完成时间</th>
                                <th lay-data="{fixed: 'right', width:210, align:'center', toolbar: '#barDemo'}">操作</th>
                            </tr>
                            </thead>
                        </table>
                        <script id="barDemo" type="text/html">
                            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
                            <a class="layui-btn layui-btn-xs" lay-event="over">完成任务</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="detail">上传文件</a>
                        </script>
                    </div>

                </div>
            </div>
            <div class="layui-tab-item layui-show">
                <div class="layui-row layui-col-space15">
                    <div class="layui-col-md12">
                        <fieldset class="layui-elem-field layui-field-title">
                            <legend>我的任务--<?php echo $user; ?></legend>
                        </fieldset>
                        <table class="layui-table" lay-data="{ height:500, url:'../../php/user/query_task_user.php?user=<?php echo $user ?>', page:true, id:'idTestA'}" lay-filter="demoA">
                            <thead>
                            <tr>
                                <th lay-data="{field:'id', width:80, sort: true, fixed: true}">任务ID</th>
                                <th lay-data="{field:'content', width:150}">任务详情</th>
                                <th lay-data="{field:'create_time', width:200}">发布时间</th>
                                <th lay-data="{field:'over_time', width:200}">截至时间</th>
                                <th lay-data="{field:'complete', width:200}">完成时间</th>
                                <th lay-data="{fixed: 'right', width:200, align:'center', toolbar: '#barDemoA'}">操作</th>
                            </tr>
                            </thead>
                        </table>
                        <script id="barDemoA" type="text/html">
                            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detailA">查看</a>
                            <a class="layui-btn layui-btn-xs" lay-event="update_over">完成任务</a>
                            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
                        </script>
                    </div>

                </div>
            </div>
            <div class="layui-tab-item layui-show">
                <div class="layui-row layui-col-space15">
                    <legend><i class="iconfont" style="color: #0b3b8c">&#xe6b2;写任务：</i></legend>
                    <div class="layui-form-item">
                        <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>任务详情：</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" maxlength="500" id="content" name="content" placeholder="请输入内容,内容字数不超过500字"></textarea>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label login-form" id="title-form"><i class="layui-icon-util" style="color: #0b3b8c">&#xe631;</i>设置任务完成时间：</label>
                        <div class="layui-input-inline">
                            <input name="date" class="layui-input" id="date" type="text" placeholder="2018年6月1日" autocomplete="off" lay-verify="date">
                            <input name="user" id="user"style="display: none" value="<?php echo $user; ?>" />

                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label login-form" id="title-form"><i class="iconfont" style="color: #0b3b8c">&#xe6b8;</i>备注：</label>
                        <div class="layui-input-block">
                            <textarea class="layui-textarea" maxlength="500" id="bei" name="bei" placeholder="请输入内容,内容字数不超过500字"></textarea>
                        </div>
                    </div>
                    <br>
                    <button class="btn btn-warning " lay-submit lay-filter="login" style="float: right" onclick="release()" type="button">确认发布</button>
                </div>
            </div>
        </div>
    </div>



</div>


<ins class="adsbygoogle" style="display:inline-block;width:970px;height:90px" data-ad-slot="3820120620" data-ad-client="ca-pub-6111334333458862"></ins>

<script src="../../static/js/jquery.min.js"></script>
<script src="../../static/js/layui/layui.all.js"></script>
<script>
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择alert(count);
        table.on('checkbox(demo)', function(obj){
            console.log(obj);

        });
        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'detail'){
            window.location.href="show.html?id="+data.id;




            }

            else if(obj.event === 'del'){
                $id=data.id;
                layer.confirm('真的删除行么', function(index) {
                    member_del($id);
                    obj.del();
                    layer.close(index);
                });
            } else if(obj.event === 'over'){

                    layer.confirm('您确定已经完成任务并上传了文件吗？', function(index) {
                        $.ajax({
                            type: 'post',
                            cache: false,
                            url: '../../php/user/update_time.php',
                            data: {
                                "id":data.id,
                            },
                            dataType: 'json',
                            success: function (data) {
                                layer.msg(data.message);
                            },
                            error: function (data) {
                                layer.msg("更新状态失败");
                            }
                        });


                    });



            }
        });


        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    layui.use('table', function(){
        var table = layui.table;
        //监听表格复选框选择alert(count);
        table.on('checkbox(demoA)', function(obj){
            console.log(obj);

        });
        //监听工具条
        table.on('tool(demoA)', function(obj){
            var data = obj.data;
            if(obj.event === 'detailA'){
                window.location.href="view.html?id="+data.id;
            }
            else if(obj.event === 'del'){
                $id=data.id;
                layer.confirm('真的删除行么', function(index) {
                    $.ajax({
                        type: 'post',
                        cache: false,
                        url: '../../php/user/del_task.php',
                        data: {
                            "id":data.id,
                        },
                        dataType: 'json',
                        success: function (data) {
                            layer.msg(data.message);
                            obj.del();
                            layer.close(index);
                        },
                        error: function (data) {
                            layer.msg("删除失败");
                        }
                    });


                });
            }
            else if(obj.event === 'update_over'){
                layer.confirm('您确定已经完成任务并上传了文件吗？', function(index) {
                    $.ajax({
                        type: 'post',
                        cache: false,
                        url: '../../php/user/update_time_self.php',
                        data: {
                            "id":data.id,
                        },
                        dataType: 'json',
                        success: function (data) {
                            layer.msg(data.message);
                        },
                        error: function (data) {
                            layer.msg("更新状态失败");
                        }
                    });


                });
            }
        });



        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
    if($('#user').val()===""){
        layer.msg("您还没有登陆哦！");
        window.location.href="../loginU.html";

    }
    var user=document.getElementById("user");
    $user=user.value;
    //获取任务信息


    var uploadUrl = '../../php/user/upload.php';
    //文件选择完毕时
    function FileChangeFn(event) {
        $('.opst_txt').text('重新选择文件');
        $('.send_btn').show();
        var event = event || window.event,
            dom = '',
            ofile = $("#oFile").get(0).files[0],
            otype = ofile.type || '获取失败',
            osize = ofile.size / 1054000,
            ourl = window.URL.createObjectURL(ofile); //文件临时地址
        $('#file_type').text("选择上传文件类型：" + otype);
        $('#file_size').text("选择上传文件大小，共" + osize.toFixed(2) + "MB。");

        console.log("文件类型：" + otype); //文件类型
        console.log("文件大小：" + osize); //文件大小

        if ('video/mp4' == otype || 'video/avi' == otype || 'video/x-msvideo' == otype) {
            layer.msg("请上传压缩文件/或者图片");
        }
        if ('audio/mp3' == otype || 'audio/wav' == otype  || 'audio/x-m4a' == otype) {
            layer.msg("请上传压缩文件/或者图片");
        }
        if ('image/jpeg' == otype || 'image/png' == otype || 'image/gif' == otype) {
            dom = '<img id="photo" width="100%"  alt="我是image图片文件" src=' + ourl + ' title="" />';
        }
        if ('zip' == otype) {
            dom = '<img id="photo" width="100%"  alt="我是压缩文件" src=' + ourl + ' title="" />';
        }
        $('#file_box').html(dom);
    };

    //侦查附件上传情况 ,这个方法大概0.05-0.1秒执行一次
    function OnProgRess(event) {
        var event = event || window.event;
        //console.log(event);  //事件对象
        console.log("已经上传：" + event.loaded); //已经上传大小情况(已上传大小，上传完毕后就 等于 附件总大小)
        //console.log(event.total);  //附件总大小(固定不变)
        var loaded = Math.floor(100 * (event.loaded / event.total)); //已经上传的百分比
        $("#speed").html(loaded + "%").css("width", loaded + "%");
    };

    //开始上传文件
    function UploadFileFn() {


        var file=document.getElementById("oFile");
        fileV=file.value;
        if(fileV===""){
            layer.msg("您还没有选择任何文件哦")
        }
        else {

            $('.speed_box').show();
            var oFile = $("#oFile").get(0).files[0], //input file标签
                formData = new FormData(); //创建FormData对象
            xhr = $.ajaxSettings.xhr(); //创建并返回XMLHttpRequest对象的回调函数(jQuery中$.ajax中的方法)
            formData.append("myFile", oFile); //将上传name属性名(注意：一定要和 file元素中的name名相同)，和file元素追加到FormData对象中去

            $.ajax({
                type: "POST",
                url: uploadUrl, // 后端服务器上传地址
                data: formData, // formData数据
                cache: false, // 是否缓存
                async: true, // 是否异步执行
                processData: false, // 是否处理发送的数据  (必须false才会避开jQuery对 formdata 的默认处理)
                contentType: false, // 是否设置Content-Type请求头
                dataType: 'json',
                xhr: function () {
                    if (OnProgRess && xhr.upload) {
                        xhr.upload.addEventListener("progress", OnProgRess, false);
                        return xhr;
                    }
                },
                success: function (dat) {

                    $("#speed").html("上传成功");
                    var url=document.getElementById("img-url");
                    url.value=dat.src;
                },
                error: function (dat) {
                    $("#speed").html("上传失败");

                    layer.msg('请正确配置后台服务！');
                }
            });
        }
    }

    //日期
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form
            ,layer = layui.layer
            ,layedit = layui.layedit
            ,laydate = layui.laydate;

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

    });
    var admin=document.getElementById("admin").value;
    $.ajax({
        type: 'post',
        cache: false,
        url: '../../php/admin/select_notice.php',
        data: {
          "user":admin,
        },
        dataType: 'json',
        success: function (data) {
            $dat = data.data
            $coun = data.count;
            $notice=$dat[0].content;
            var not=document.getElementById("notice");
            not.innerHTML=$notice;

            for ($i = 0; $i < $coun; $i++) {
                $id = $dat[$i].id;
                $user = $dat[$i].no_admin;
                $title=$dat[$i].title;
                $content=$dat[$i].content;
                $addtime=$dat[$i].no_addtime;
                var date=new Date(parseInt($addtime)*1000);
                Y=date.getFullYear()+'年';
                M=(date.getMonth()+1<10?'0'+(date.getMonth()+1):date.getMonth()+1)+'月';
                D=date.getDate()+'日';
                h=date.getHours()+':';
                m=date.getMinutes()+':';
                s=date.getSeconds();
                $date=Y+M+D+h+m+s;
                if($i===0){
                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                        "                        <i class=\"layui-icon layui-timeline-axis\"></i>\n" +
                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                        "                            <div class=\"layui-timeline-title\">"+$date+"&nbsp;&nbsp;"+"主题："+$title+"&nbsp;&nbsp;内容："+$content+"</div>\n" +
                        "                        </div>\n" +
                        "                    </li>");
                }
                else if($i===$coun-1) {
                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                        "<i class=\"layui-icon layui-anim layui-anim-rotate layui-anim-loop layui-timeline-axis\"></i>"+
                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                        "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                        "                        </div>\n" +
                        "                    </li>");

                }
                else {
                    $li = $(" <li class=\"layui-timeline-item\">\n" +
                        "<i class=\"layui-icon layui-timeline-axis\"></i>"+
                        "                        <div class=\"layui-timeline-content layui-text\">\n" +
                        "                            <div class=\"layui-timeline-title\">" + $date + "&nbsp;&nbsp;" + "主题：" + $title + "&nbsp;&nbsp;内容：" + $content + "</div>\n" +
                        "                        </div>\n" +
                        "                    </li>");

                }
                $("#notice-list").append($li);
            }


        },
        error: function (data) {
        }
    });

    function release() {
        var content=document.getElementById("content").value,
             dateTime=document.getElementById("date").value,
             user=document.getElementById("user").value,
            bei=document.getElementById("bei").value;

        $.ajax({
            type: 'post',
            cache: false,
            url: '../../php/user/add_task.php',
            data: {
                "user":user,
                "content":content,
                "over_time":dateTime,
                "bei":bei,
            },
            dataType: 'json',
            success: function (data) {
                layer.msg(data.message);

            },
            error: function (data) {
                layer.msg("获取数据异常");
            }
        });


    }


    function out() {
        layer.confirm('真的要退出吗？', function(index) {
            window.location.href="../../php/user/clearSession.php";
        })
    }


</script>

</body>
</html>